
local message   = require 'jass.message'
local japi      = require 'jass.japi'
local console   = ac.console 

-- 范围指示器
local acquire = { }
setmetatable(acquire,acquire)
console.acquire = acquire
acquire.effect = ac.point(0,0):add_effect('')
acquire.effect.default = true 
acquire.state = 0 

function acquire:show()
    if self.effect and not self.show_flag then 
        self.effect:set_model('range_circle.mdx')
        self.effect:set_color(0xff00ff00)
        self.show_flag = true
    end 
end 

function acquire:hide()
    if self.effect and self.show_flag == true then 
        self.effect:set_model('.mdx')
        self.show_flag = false
    end
end 

-- 更新
function acquire.update()
    local unit = ac.unit.localunit()
    if unit and not unit.removed and acquire.state == 1 then 
        local abil_id, order_id, state = ac.message.common_selector()
        if state ~= 1 and order_id then 
            local range = 0
            if order_id == 0xD000F then 
                range = unit:get("攻击距离")
                acquire.effect:set_color(0xffff6464)
            elseif order_id >= 852008 and order_id <= 852013 then 
                local item = unit.items[order_id - 852007]
                if item then 
                    range = item:get_range()
                    acquire.effect:set_color(0xff64ff64)
                end
            elseif unit.play_skills then 
                local order = Order[order_id]
                local skill = unit:find_skill_by_order(order)
                if skill then 
                    range = format_obj(skill,skill.show_range) or skill:get_range()
                    acquire.effect:set_color(0xff64ff64)
                end 
            end
            if range > 0 and range <= 3000 then 
                local point = ac.point( unit:get_anchor_point() )
                local height = unit:get_height() + point:get_height() 
                acquire.effect:set_height(height)
                acquire.effect:set_point(point)
                acquire.effect:set_scale(range / (512 - unit:get_collision())) 
                acquire:show()
            else 
                acquire:hide()
            end
        else
            acquire:hide()
        end
    else
        acquire:hide()
    end 
end 

ac.hardware:on "界面绘制" (acquire.update)

-- ac.message:on "键盘按下" (function(t, code)
--     if not ac.game:iskeydown("CTRL") then return end
--     local player = ac.player.self
--     local unit = player.hero 
--     if not unit then return end; 
--     if code == 256 then 
--         if acquire.state == 0 then 
--             acquire.state = 1
--             ac.game:say("|cffc0c0c0范围指示器已开启|r")
--         else 
--             acquire.state = 0
--             ac.game:say("|cffc0c0c0范围指示器已关闭|r")
--         end 
--     end 
-- end)
acquire.state = 1

return acquire





